/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var increasingBST = function(root) {
  let nodeArr = [];
  function midView(node) {
    if(node.left) midView(node.left);
    nodeArr.push(node);
    if(node.right) midView(node.right);
  }
  midView(root);
  for(let i = 0; i < nodeArr.length; i++) {
    nodeArr[i].left = null;
    if(i == nodeArr.length - 1) {
      continue;
    }
    nodeArr[i].right = nodeArr[i + 1];
  }
  return nodeArr[0];
};
let root = [5,3,6,2,4,null,8,1,null,null,null,7,9];
console.log(increasingBST(root));
root = [5,1,7];
console.log(increasingBST(root));
